﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

namespace XfTechOAWeb.Infrastructure.Utilities
{
    /// <summary>
    /// 读出appsetting.json配置文件
    /// </summary>
    public class AppConfigurtaionServices
    {
        public static IConfiguration Configuration { get; set; }

        /// <summary>
        /// 静态构造方法
        /// </summary>
        static AppConfigurtaionServices()
        {
            //读取配置文件
            Configuration = new ConfigurationBuilder()
                           .Add(new JsonConfigurationSource { 
                               Path = "appsettings.json", 
                               ReloadOnChange = true 
                           })
                           .Build();
        }

        /// <summary>
        /// 获取json配置中的节点信息
        /// </summary>
        /// <param name="sections"></param>
        /// <returns></returns>
        public static string Get(params string[] sections)
        {
            try
            {

                if (sections.Any())
                {
                    return Configuration[string.Join(":", sections)];
                }
            }
            catch (Exception) { }

            return "";
        }
    }
}
